
import { request } from '@umijs/max';

export async function fetchAuditList(data) {
  const req = await request('/api/mjFlow/queryByPage', {method: 'POST', data });
  return {data:req.data.records,success:true,total:req.data.total}
}

export async function createAudit(data) {
  return request('/api/mjOrder/add', { method: 'POST', data });
}

export async function updateAudit(params) {
  return request(`/api/mjFlow/audit`, { method: 'GET', params });
}
export async function updateRefuse(params) {
  return request(`/api/mjFlow/refuse`, { method: 'GET', params });
}
// 审批详情
export async function detailAudit(id: string) {
  return request(`/api/mjFlow/detail`, { method: 'GET', params:{ id:id }});
}


export async function deleteAudit(id) {
  return request(`/api/mjFlow/delete`, { method: 'GET',params:{ id:id} });
}


export async function fetchAuditConfigList(data) {
    const req = await request('/api/mjFlowConfig/queryByPage', {method: 'POST', data });
    return {data:req.data.records,success:true}
  }
  
  export async function createAuditConfig(data) {
    data.roleCode = data?.approvalSteps?.map((item)=>item.approvalRole).join(',');
    data.sendCode = data?.copySteps?.map((item)=>item.copyNode).join(',');
    data.flowType = 2
    data.conditions = 'greaterThan'
    console.log(data,'createAuditConfig')
    return request('/api/mjFlowConfig/add', { method: 'POST', data });
  }
  
  export async function updateAuditConfig(data) {
    data.roleCode = data?.approvalSteps?.map((item)=>item.approvalRole).join(',');
    data.sendCode = data?.copySteps?.map((item)=>item.copyNode).join(',');
    return request(`/api/mjFlowConfig/edit`, { method: 'POST', data });
  }
  
  export async function deleteAuditConfig(id) {
    return request(`/api/mjFlowConfig/delete`, { method: 'GET',params:{ id:id} });
  }

  export async function withdraw(id) {
    return request(`/api/mjFlow/withdraw`, { method: 'GET',params:{ id:id} });
  }